var uid = sessionStorage.getItem("uid");
$(function () {
    var e = $("#userInfo")
        , t = function () {
            var t = sessionStorage.getItem("uid");
            t || console.error("uid not exist");
            var i = $.data(e, "uinfo");
            if (i)
                return $("#phoneNum").html(i.phone_num),
                    $("#uName").html(i.name),
                    void $("#introducer").html(i.introducer_name);
            $.get(hostUrl + "/customer/info", function (t) {
                if (!0 === t.meta.success) {
                    var i = t.data;
                    $.data(e, "uinfo", i),
                        $("#phoneNum").html(i.phone_num),
                        $("#uName").html(i.name),
                        $("#introducer").html(i.introducer_name);
                    $("#qrcode_popup_img").attr('src', i.qrcode_url);
                } else
                    $.toptip(t.meta.message, "error")
            })
        };
    (window.history && window.history.pushState && $(window).on("popstate", function () {
        window.history.forward(1)
    }),
        $("#uInfo").bind("click", function () {
            t()
        }),
        isRouterValid(),
        $("#tab1").hasClass("weui-tab__bd-item--active")) && ($("#tab1")[0].clientHeight < 600 && $(".weui-btn-area").after('<div class="weui-footer fill"><p class="weui-footer__text">&nbsp;</p></div>'));
    var i = vipspa.getMessage("person_info");
    i.content ? ($("#" + i.content.tab).click(),
        "uInfo" === i.content.tab && t()) : $("#defTab").click(),
        vipspa.clearMessage("person_info")
}),
    $("#invest_amount").picker({
        title: "请选择名义本金",
        cols: [{
            textAlign: "center",
            displayValues: ["100万", "150万", "200万", "250万", "300万", "350万", "400万", "450万", "500万", "550万", "600万", "650万", "700万", "750万", "800万", "850万", "900万", "950万", "1000万"],
            values: ["1000000", "1500000", "2000000", "2500000", "3000000", "3500000", "4000000", "4500000", "5000000", "5500000", "6000000", "6500000", "7000000", "7500000", "8000000", "8500000", "9000000", "9500000", "10000000"]
        }],
        onChange: function (e, t, i) {
            $("#invest_amount").val(t[0])
        },
        onClose: function (e) {
            var t = $("#invest_amount");
            t.val(e.value[0]);
            var i = $("#ex_quat").text();
            i && ($("#invest").text(toThousands(e.value[0])),
                $("#fixedQuat").text(toThousands(doFixedQuat(t.val() * parseFloat(i)))))
        }
    });
var doFixedQuat = function (e) {
    return 10 * Math.round(Math.ceil(e / 100) / 10)
};
$("#queryStock").on("click", function () {
    restInfo(),
        queryStock(function () { })
});
var restInfo = function () {
    $("#stockCode").text(""),
        $("#stockNm").text(""),
        $("#ex_quat").text(""),
        $("#invest").text(""),
        $("#period").text(""),
        $("#pencentage").text(""),
        $("#quat_date").text(""),
        $("#exprice_date").text(""),
        $("#fixedQuat").text(""),
        $("#invest_amount").val("")
};
$("#code").on("change", function () {
    restInfo()
});
var tabbarHeight = $(".weui-tabbar")[0].clientHeight
    , queryStock = function (e) {
        $.ajax({
            method: "POST",
            url: hostUrl + "/stock/query_stock",
            contentType: "application/json; charset=utf-8",
            data: '{ "symbols":"' + $("#code").val() + '","cycle":"' + $("#sPeriod").val() + '","price_mode":"' + $("#sPencent").val() + '"  }',
            success: function (t) {
                if (!0 === t.meta.success) {
                    var a = t.data;
                    if (a && a.length > 0) {
                        $("#stock_container")[0] && $("#stock_container").remove();
                        for (var n = $("<div class='stock-mask_transparent'></div>").appendTo(document.body),
                            s = '<div class="stock_search_container" id="stock_container"  style="max-height:' + (document.body.clientHeight - ($("#periodDiv").offset().top + tabbarHeight)) + "px;top:" + ($("#periodDiv").offset().top + 2) + 'px"><div class="search_stock_item " style="display: block;">\n                            <div class="stock_code">股票代码</div>\n                            <div class="stock_name">股票名称</div>\n                            <div class="quotation">管理费率</div>\n                        </div> ', l = 0; l < a.length; l++) {
                            var o = a[l];
                            s += '<div class="search_stock_item" style="display: block;">\n' +
                                '<div class="SYMBOL" insure="' + o.insure_date + '" expire="' + o.expire_date + '">' + o.symbol + '</div>\n                            <div class="SYMBOL_NAME" circle="' + o.cycle + '">' + o.symbol_name + '</div>\n                            <div class="EXTERNAL_QUOTATION" pencent="' + o.price_mode + '">' + o.offer_price + "%</div>\n                        </div>"
                        }
                        s += "</div>",
                            $(document.body).append(s);
                        var r = $("#stock_container");
                        r.on("click", ".search_stock_item", function () {
                            var t = $("#code");
                            $(this).find(".SYMBOL").text() && (t.val($(this).find(".SYMBOL").text()),
                                $("#stockCode").text($(this).find(".SYMBOL").text()),
                                t.attr("sNm", $(this).find(".SYMBOL_NAME").text()),
                                $("#stockNm").text($(this).find(".SYMBOL_NAME").text()),
                                t.attr("quat", $(this).find(".EXTERNAL_QUOTATION").text()),
                                $("#ex_quat").text($(this).find(".EXTERNAL_QUOTATION").text()),
                                $("#period").text($(this).find(".SYMBOL_NAME").attr("circle").substr(0, 1) + "个月"),
                                $("#exprice_date").text(formatDate($(this).find(".SYMBOL").attr("expire"))),
                                $("#exprice_date").attr("ex", $(this).find(".SYMBOL").attr("expire")),
                                $("#quat_date").text(formatDate($(this).find(".SYMBOL").attr("insure"))),
                                $("#quat_date").attr("ex", $(this).find(".SYMBOL").attr("insure")),
                                $("#pencentage").text($(this).find(".EXTERNAL_QUOTATION").attr("pencent") + "%"),
                                r.remove(),
                                n.remove(),
                                e())
                        })
                    } else
                        $.hideLoading(),
                            0 === i.content.Data_list.length ? $.toptip("股票代码不正确！") : $.toptip(i.errDesc, "error")
                } else
                    $.hideLoading(),
                        $.toptip(t.meta.message, "error")
            }
        })
    }
    , $investAmount = $("#invest_amount");
$investAmount.on("change", function () {
    changeInvest()
}),
    $("#invest").on("change", function () {
        $("#fixedQuat").text(toThousands(doFixedQuat($(this).val() * parseFloat($("#ex_quat").text()))))
    });
var changeInvest = function () {
    var e = $("#invest_amount").val();
    $("#ex_quat").text() && e && ($("#invest").text(toThousands(e)),
        $("#fixedQuat").text(toThousands(doFixedQuat(e * parseFloat($("#ex_quat").text())))))
}
    , resetInvest = function () {
        changeInvest()
    };
function getInquiryRec() {
    $("#xjjl").html(""),
        $("#loadXj").css("display", "");
    var e = "";
    $.get(hostUrl + "/stock/inquiry?uid=" + uid, function (t, i) {
        if (!0 === t.meta.success) {
            for (var a = 0; a < t.data.length; a++) {
                var n = t.data[a];
                e += '<div class="weui-form-preview">\n' +
                    '   <div class="weui-form-preview__bd">\n' +
                    '       <div class="weui-flex">\n' +
                    '           <div class="weui-flex__item">\n' +
                    '               <div class="">\n' +
                    '                   <label class="weui-form-preview__label">股票代码</label>\n' +
                    '                   <span class="mr5">' + n.stock_code + '</span>\n' +
                    '               </div>\n' +
                    '           </div>\n' +
                    '       <div class="weui-flex__item ">\n                            <div class="">\n' +
                    '<label class="weui-form-preview__label">股票名称</label>\n' +
                    '                                <span class="">' + n.stock_name + '</span>\n' +
                    '                            </div>\n                        </div>\n                    </div>\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">管理费</label>\n' +
                    '                                <span class="mr5">' + toThousands(n.deposit_amount) + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">名义本金</label>\n' +
                    '                                <span class="">' + toThousands(n.invest_amount) + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">行权周期</label>\n' +
                    '                                <span class="mr5">' + n.period + '个月</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">行权价格</label>\n' +
                    '                                <span class="">' + n.percentage + '%</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">报价日期</label>\n' +
                    '                                <span class="mr5">' + n.quote_date.replace(" 00:00:00", "") + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">到期日期</label>\n' +
                    '                                <span class="">' + n.due_date.replace(" 00:00:00", "") + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">备注</label>\n',
                    n.reject_note && (e += '<span class="color-primary">交易驳回: ' + n.reject_note + "</span>\n"),
                    e += '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '                    <div class="weui-btn-area weui-btn-area_inline">\n' +
                    '                        <a class="weui-btn weui-btn_primary" stock="' + n.stock_name + '" name="buyDel" ex="' + n.id + '" href="javascript:" >删除</a>\n' +
                    '                        <a class="weui-btn weui-btn_warn" quote_date="' + n.quote_date + '" stock="' + n.stock_name + '" name="buyAdd" ex="' + n.id + '" quote="' + n.deposit_amount + '"" href="javascript:" >申请买入</a>\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '            </div>'
            }
            t.data.length >= 3 && (e += '<div class="weui-footer fill">\n' +
                '  <p class="weui-footer__text">没有更多了</p>\n' +
                '</div>'),
                $("#xjjl").html(e),
                $("#loadXj").css("display", "none")
        }
    })
}
function getPosition() {
    $("#loadCc").css("display", ""),
        $("#ccjl").html("");
    var e = "";
    $.get(hostUrl + "/stock/position", function (t, i) {
        if (!0 === t.meta.success) {
            for (var a = 0; a < t.data.length; a++) {
                var n = t.data[a];
                e += '<div class="weui-form-preview">\n' +
                    '                <div class="weui-form-preview__bd">\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="">\n' +
                    '                                <label class="weui-form-preview__label ">股票代码</label>\n' +
                    '                                <span class="mr5">' + n.stock_code + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                        <div class="weui-flex__item ">\n' +
                    '                            <div class="">\n' +
                    '                                <label class="weui-form-preview__label ">股票名称</label>\n' +
                    '                                <span class="">' + n.stock_name + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">管理费</label>\n' +
                    '                                <span class="mr5">' + toThousands(n.deposit_amount) + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">名义本金</label>\n' +
                    '                                <span class="">' + toThousands(n.invest_amount) + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">期初价</label>\n' +
                    '                                <span class="mr5">' + (n.buy_price ? n.buy_price.toFixed(2) : "") + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">合约状态</label>\n' +
                    '                                <span class="weui-cell_warn">' + getState(n.status) + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">报价日期</label>\n' +
                    '                                <span class="mr5">' + n.quote_date.replace(" 00:00:00", "") + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">到期日期</label>\n' +
                    '                                <span class="">' + n.due_date.replace(" 00:00:00", "") + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">买入日期</label>\n' +
                    '                                <span class="">' + (n.buy_date ? n.buy_date : "") + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">备注</label>\n',
                    n.reject_note && (e += '<span class="color-primary">交易驳回: ' + n.reject_note + "</span>\n"),
                    e += '                            </div>\n                        </div>\n                    </div>\n                    <div class="weui-btn-area weui-btn-area_inline" >\n' + getBtnState(n.status, n.id, n.stock_name) + "                    </div>\n                </div>\n            </div>"
            }
            t.data.length >= 3 && (e += '<div class="weui-footer fill">\n  <p class="weui-footer__text">&nbsp;</p>\n</div>'),
                $("#ccjl").html(e),
                $("#loadCc").css("display", "none")
        }
    })
}
function getHistory() {
    $("#loadHis").css("display", ""),
        $("#jyjl").html("");
    var e = "";
    $.get(hostUrl + "/stock/history", function (t, i) {
        if (!0 === t.meta.success) {
            t.data = t.data.content;
            for (var a = 0; a < t.data.length; a++) {
                var n = t.data[a];
                e += '<div class="weui-form-preview">\n' +
                    '                <div class="weui-form-preview__bd">\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="">\n' +
                    '                                <label class="weui-form-preview__label ">股票代码</label>\n' +
                    '                                <span class="mr5">' + n.stock_code + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                        <div class="weui-flex__item ">\n' +
                    '                            <div class="">\n' +
                    '                                <label class="weui-form-preview__label ">股票名称</label>\n' +
                    '                                <span class="">' + n.stock_name + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">管理费</label>\n' +
                    '                                <span class="mr5">' + toThousands(n.deposit_amount) + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">名义本金</label>\n' +
                    '                                <span class="">' + toThousands(n.invest_amount) + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">期初价</label>\n' +
                    '                                <span class="mr5">' + n.buy_price + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">行权价</label>\n' +
                    '                                <span class="">' + n.sell_price + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">合约状态</label>\n' +
                    '                                <span class="weui-cell_warn mr5">' + getState(n.status) + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">收益</label>\n' +
                    '                                <span class="weui-cell_warn">' + toThousands(n.profit) + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">买入日期</label>\n' +
                    '                                <span class="">' + n.buy_date + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '                    <div class="weui-flex">\n' +
                    '                        <div class="weui-flex__item">\n' +
                    '                            <div class="weui-form-preview__item">\n' +
                    '                                <label class="weui-form-preview__label">行权日期</label>\n' +
                    '                                <span class="">' + n.sell_date + '</span>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '            </div>'
            }
            t.data.length >= 3 && (e += '<div class="weui-footer fill">\n  <p class="weui-footer__text">&nbsp;</p>\n</div>'),
                $("#jyjl").html(e),
                $("#loadHis").css("display", "none")
        }
    })
}
function getState(e) {
    switch (e) {
        case 1:
            return "询价中";
        case 2:
            return "买入中";
        case 4:
            return "已买入";
        case 5:
            return "行权中";
        case 7:
            return "未定义7";
        case 8:
            return "交易完成"
    }
}
function getBtnState(e, t, i) {
    switch (e) {
        case 2:
            return '<a class="weui-btn weui-btn_warn weui-btn_disabled" href="javascript:">买入中...</a>';
        case 4:
            return '<a class="weui-btn weui-btn_warn" ex="sell" stock="' + i + '" cid="' + t + '" href="javascript:">申请行权</a>';
        case 5:
        case 7:
            return '<a class="weui-btn weui-btn_warn weui-btn_disabled" href="javascript:">行权中...</a>';
        case 8:
            return ""
    }
}
$("#sPencent").on("change", function () {
    $("#stockCode").text(""),
        $("#stockNm").text(""),
        $("#ex_quat").text(""),
        $("#invest").text(""),
        $("#period").text(""),
        $("#pencentage").text(""),
        $("#quat_date").text(""),
        $("#exprice_date").text(""),
        $("#fixedQuat").text(""),
        $("#invest_amount").val("")
}),
    $investAmount.on("focus", function () {
        !$("#stockCode").text() || $("#stockNm").text()
    }),
    $("#sPeriod").on("change", function () {
        $("#stockCode").text(""),
            $("#stockNm").text(""),
            $("#ex_quat").text(""),
            $("#invest").text(""),
            $("#period").text(""),
            $("#pencentage").text(""),
            $("#quat_date").text(""),
            $("#exprice_date").text(""),
            $("#fixedQuat").text(""),
            $("#invest_amount").val("")
    }),
    $("#addTrade").on("click", function () {
        if (!$("#stockCode").text() || !$("#stockNm").text())
            return $.toptip("请先获取期权信息", "error"),
                void $("#code").focus();
        var e = $("#invest_amount");
        if (!e.val())
            return $.toptip("请选择名义本金", "error"),
                void e.focus();
        var t = $("#sPencent").val()
            , i = $("#code")
            , a = e.val()
            , n = doFixedQuat(parseFloat(i.attr("quat")) * a);
        $.confirm({
            title: "确认提交询价",
            text: "股票名称：" + i.attr("snm") + "<br> 股票代码：" + i.val() + "<br>名义本金：" + toThousands(a) + "<br>行权周期：" + $("#sPeriod").val() + "个月<br>行权价格：" + t + "%<br>管理费：" + toThousands(n) + "<br>",
            onOK: function () {
                $.ajax({
                    method: "post",
                    url: hostUrl + "/stock/add",
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify({
                        "user_id": uid,
                        "stock_code": i.val(),
                        "stock_name": i.attr("snm"),
                        "invest_amount": a,
                        "deposit_amount": n,
                        "quote_date": formatDate($("#quat_date").attr("ex")) + ' 00:00:00',
                        "due_date": formatDate($("#exprice_date").attr("ex")) + ' 00:00:00',
                        "period": $("#sPeriod").val(),
                        "percentage": $("#sPencent").val()
                    }),
                    success: function (e) {
                        !0 === e.meta.success ? ($.toptip("操作成功", "success"),
                            restInfo(),
                            $("#code").val("")) : $.toptip(e.meta.message)
                    }
                })
            },
            onCancel: function () { }
        })
    }),
    $("#tabxj").bind("click", function () {
        getInquiryRec()
    }),
    $("#tabCc").bind("click", function () {
        getPosition()
    }),
    $("#tabJl").bind("click", function () {
        getHistory()
    }),
    $("#xjjl").on("click", "a", function () {
        var e = $(this).attr("ex")
            , t = $(this).attr("name")
            , i = $(this).attr("stock")
            , a = $(this).attr("quote_date")
            , n = $(this).attr("quote");
        if ("buyDel" === t)
            $.confirm({
                title: "确认删除？",
                text: "确认删除<" + i + ">的询价记录吗？",
                onOK: function () {
                    $.ajax({
                        method: "post",
                        url: hostUrl + "/stock/delete",
                        contentType: "application/json; charset=utf-8",
                        data: '{\n    "id" : "' + e + '"}',
                        success: function (e) {
                            !0 === e.meta.success ? ($.toptip("删除成功", "success"),
                                getInquiryRec()) : $.toptip(e.meta.message)
                        }
                    })
                }
            });
        else {
            if (addDate(stringToDate(a.replace(" 00:00:00", "")), 2) < stringToDate((new Date).format("yyyy-MM-dd")))
                return void $.toptip("该询价记录已过期，请重新询价后再提交");
            $.buyLimit({
                title: "<" + i + ">买入申请",
                onOK: function (t, i, a) {
                    t = "1" === i ? "" : t,
                        $.ajax({
                            method: "post",
                            url: hostUrl + "/stock/buy",
                            contentType: "application/json; charset=utf-8",
                            data: JSON.stringify({
                                "id": e,
                                "password": a,
                                "user_id": uid,
                                "buy_type": i,
                                "quote": n,
                                "buy_limit_price": t
                            }),
                            success: function (e) {
                                !0 === e.meta.success ? ($.toptip("买入成功", "success"),
                                    getInquiryRec()) : $.toptip(e.meta.message)
                            }
                        })
                },
                onCancel: function () { }
            })
        }
    }),
    $("#logout").on("click", function () {
        $.confirm("确定注销吗？", function () {
            sessionStorage.clear(),
                $.data(userInfo, "uinfo", null),
                uid = null,
                setTimeout(function () {
                    location.hash = "login"
                }, 300)
        }, function () { })
    }),
    $("#modifyPass").on("click", function () {
        location.hash = "pass-manage"
    }),
    $("#bankInfo").on("click", function () {
        location.hash = "bank-info"
    }),
    $("#capital").on("click", function () {
        location.hash = "capital"
    }),
    $("#ccjl").on("click", "a", function () {
        var e = $(this).attr("cId")
            , t = $(this).attr("ex");
        $(this).attr("stock");
        "cancelBuy" === t || "cancelSell" === t || "sell" === t && $.buyLimit({
            title: "行权申请",
            onOK: function (t, i, a) {
                t = "1" === i ? "" : t,
                    $.ajax({
                        method: "post",
                        url: hostUrl + "/stock/sell",
                        contentType: "application/json; charset=utf-8",
                        data: JSON.stringify({
                            "id": e,
                            "password": a,
                            "sell_type": i,
                            "sell_limit_price": t
                        }),
                        success: function (e) {
                            !0 === e.meta.success ? (getPosition(),
                                $.toptip("已接收您的行权指令，下一交易日执行", "success")) : $.toptip(e.meta.message)
                        }
                    })
            },
            onCancel: function () { }
        })
    }),
    $(".weui-tabbar__item").on("click", function (e) {
        if ($(this).hasClass("weui-bar__item--on"))
            return e.preventDefault(),
                !1
    }),
    Date.prototype.format = function (e) {
        var t = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),
            S: this.getMilliseconds()
        };
        for (var i in /(y+)/.test(e) && (e = e.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length))),
            t)
            new RegExp("(" + i + ")").test(e) && (e = e.replace(RegExp.$1, 1 == RegExp.$1.length ? t[i] : ("00" + t[i]).substr(("" + t[i]).length)));
        return e
    }
    ;
var toThousands = function (e) {
    return (e || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, "$1,")
}
    , formatDate = function (e) {
        return e && 8 === e.length ? e.substr(0, 4) + "-" + e.substr(4, 2) + "-" + e.substr(6, 2) : "9999-12-12"
    }
    , stringToDate = function (e) {
        var t = e.split("-");
        return new Date(t[0], t[1] - 1, t[2], 0, 0, 0)
    }
    , addDate = function (e, t) {
        var i = new Date(e);
        i.setDate(i.getDate() + t);
        i.getMonth();
        return i
    };
$("#caozuo").click("on", function () {
    var text = '    <div style="text-align: justify;color:black">' +
        '        <br>' +
        '        <b>以下细则内，甲方作为贝塔期权询价系统的运营主体公司；乙方则是注册贝塔期权询价系统的用户。</b>' +
        '        <br>' +
        '        <br>甲方：杭州贝塔投资管理有限公司' +
        '        <br>' +
        '        <br>乙方（投资顾问）：' +
        '        <u> 注册用户 </u>' +
        '        <br>' +
        '        <br>鉴于：' +
        '        <br>甲方是政府部门批准成立的公司，旗下有经过中国证券投资基金业协会批准备案的基金公司及有与期货公司成立的并经过中国证券投资基金协会备案的私募资管产品，具备与证券公司，期货公司进行证券期货场外衍生品交易的资质；' +
        '        <br>乙方必须保证具有丰富的证券投资经验，具备合格投资者资格，以及抗风险能力，乙方作为中华人民共和国境内具有完全民事行为能力的自然人，在充分了解证券期货场外衍生市场风险和责任的前提下，注册成为甲方的用户并成为为甲方提供投资建议的投资顾问；乙方拟向甲方提供投资建议，参与证券期货场外衍生品市场。' +
        '        <br>' +
        '        <br>一、询价' +
        '        <br>1、乙方通过甲方询价系统进行询价，询价应包括但不限于：交易时间、交易标的、交易方向、交易价格及交易量。交易日内均可通过系统进行询价。' +
        '        <br>2、当日询价，非当日下单，个别股票期权费率会有变动，请下单当天再次询价。' +
        '        <br>3、非交易日内询价，询价系统显示的是上一交易日费率，个别股票在非交易日内结束后会有较大变动，请交易日内再次询价。' +
        '        <br>' +
        '        <br>二、成交' +
        '        <br>1、如乙方确认交易，乙方应将相应投资建议费用（期权费）支付至甲方指定账户。乙方再通过询价系统向甲方发出准确的交易指令，甲方中台把乙方准确的交易指令发送给证券公司。提交下单指令后，以收到款时间为准计算。' +
        '        <br>2、甲方通过系统中台向乙方发送证券公司的回馈指令（成交和未成交）时，如因乙方未能及时反馈问题而造成的损失，皆由乙方独立承担；' +
        '        <br>3、在交易日内下午14点30分之前完成下单指令以及汇款，方可当天成交，否则隔日成交。券商接受下单指令后，下单指令不可更改撤销特别说明的是，具体成交结果以证券公司成交为准。若未成交，退回款项或者作为再次交易的定金。' +
        '        <br>三、结算' +
        '        <br>1、需提前一个交易日提交行权指令。' +
        '        <br>2、到期后不提交，按券商自动行权处理，不得有异议。' +
        '        <br>3、标的到期价格低于买入价，合约到期自动解除按下单券商处理为准。' +
        '        <br>4、乙方在询价系统上发出行权建议指令，甲方中台将乙方建议指令向证券公司发送，由证券公司进行结算收益，证券公司结算时间为3个交易日内，甲方收到款项后1个交易日内将该笔交易收益支付至乙方指定账户。' +
        '        <br>5、乙方注册成功时代表确认接受《附件》所载明的交易细节，同意甲方在《附件》所约定的范围内代为处理。' +
        '        <br>四：投资建议费用' +
        '        <br>1、甲乙双方确认由乙方提出的投资建议进行交易证券期货场外衍生品所产生的费用均由乙方承担，包括但不限于期权费、询价费等与交易有关的一切费用。' +
        '        <br>' +
        '        <br>五：账户信息' +
        '        <br>甲乙双方对指定账户信息承担资金安全责任。' +
        '        <br>甲方指定法人账户信息：' +
        '        <br>' +
        '        <font color="red">户名： 杭州贝塔投资管理有限公司 </font>' +
        '        <br>' +
        '        <font color="red">账号：3301040160004845296  </font>' +
        '        <br>' +
        '        <font color="red">开户行：杭州银行石桥支行 </font>' +
        '        <br> 乙方指定账户信息：乙方注册时信息为准。' +
        '        <br> 甲方三方托管账户正在测试之中，后期在系统2.0版的时候启用三方托管账户，请知悉。' +
        '        <br>' +
        '        <br>六：联系方式' +
        '        <br>甲方：' +
        '        <br>联系人： 场外衍生品部 ' +
        '        <br>联系电话：0571-86656980' +
        '        <br>电子邮箱：393357114@qq.com ' +
        '        <br> 乙方：注册账户时信息为准。' +
        '        <br>七：注意事项' +
        '        <br>1、乙方向甲方提出投资建议，应遵守《中国证券期货市场场外衍生品交易主协议（2014年版）》、《中国证券期货市场场外衍生品交易主协议（2014年版）补充协议》相关条款。' +
        '        <br>八：其他' +
        '        <br>1、本细则作为电子协议，当乙方成功注册为甲方用户时代表已经同意本细则内容，并有法律效应。' +
        '        <br>2、本细则履行过程中产生的争议，由各方协商解决，若协商不成向甲方所在地法院提起诉讼。' +
        '        <br>' +
        '        <br>' +
        '        <b>乙方注册成功为甲方用户表明已经同意以上细则及附件</b>。' +
        '        <br>' +
        '        <br>' +
        '    </div>    '
    $.modal({
        title: "贝塔期权细则",
        text: text,
        buttons: [{
            text: "关闭",
            onClick: function () { }
        }]
    }, function () { }, "weui-read-me")
});
